package
{
	import flash.utils.getTimer;
	
	public class CGameScoreManager
	{
		public static const MAX_LEVEL_CPF	:uint = 5;
		private const COUNT_GOLD_FROM_COIN	:uint = 1;
		private const COUNT_GOLD_FROM_GOLD	:uint = 5;
		private const COUNT_FOR_ADD_PIECE	:uint = 5;
		
		private static var m_instance :CGameScoreManager = new CGameScoreManager();
		private var m_nMungLength :int;
		private var m_nEatedFoodCount :int;
		private var m_nGold :int;
		private var m_nCreamPuffFactoryLevel :int;
		private var m_nElapsedTime :Number;
		private var m_nScore :int;
		private var m_nHighestMungLength :int;
		private var m_bIsSuccess :Boolean;
		
		private var m_nAddPieceCount :int;
		
		public static function get instance() :CGameScoreManager { return m_instance; }
		public function get nMungLength() :int { return m_nMungLength; }
		public function get nHighestMungLength() :int { return m_nHighestMungLength; }
		public function get nEatedFoodCount() :int { return m_nEatedFoodCount; }
		public function get nGold() :int { return m_nGold; }
		public function get nCreamPuffFactoryLevel() :int { return m_nCreamPuffFactoryLevel; }
		public function get nElapsedTime() :Number { return m_nElapsedTime; }
		public function get nScore() :int { return m_nScore; }
		public function get bIsSuccess() :Boolean { return m_bIsSuccess; }

		public function set bIsSuccess(bIs :Boolean) :void { m_bIsSuccess = bIs; }
		
		public function CGameScoreManager()
		{
			Clear();
			m_nAddPieceCount = 0;
		}
		public function Update(tick :Number) :void
		{
			m_nElapsedTime += tick;
		}
		public function Clear() :void
		{
			m_nMungLength = 0;
			m_nEatedFoodCount = 0;
			m_nCreamPuffFactoryLevel = 0;
			m_nGold = 0;
			m_nElapsedTime = 0;
			m_nScore = 0;
			m_nHighestMungLength = 0;
			m_bIsSuccess = false;
		}
		public function ClearWithoutStaticGameData() :void
		{
			/// 고정되는 게임 데이터는 초기화 하지 않습니다.
			/// Gold
			/// Score
			/// HighestMungLength
			var nTemp_Gold :int = m_nGold;
			var nTemp_Score :int = m_nScore;
			var nTemp_HighestMungLength :int = m_nHighestMungLength;
			
			Clear();
			
			m_nGold = nTemp_Gold;
			m_nScore = nTemp_Score;
			m_nHighestMungLength = nTemp_HighestMungLength;
		}
		public function IncreaseEatedFood() :void
		{
			m_nEatedFoodCount++;
		}
		public function DecreaseGold(nAmount :int) :void
		{
			m_nGold -= nAmount;
			
			if (m_nGold < 0) m_nGold = 0;
		}
		public function AddGoldFromCoin() :void
		{
			m_nGold += COUNT_GOLD_FROM_COIN;
		}
		public function AddGoldFromGold() :void
		{
			m_nGold += COUNT_GOLD_FROM_GOLD;
		}
		public function IncreaseCreamPuffFactoryLevel() :void
		{
			m_nCreamPuffFactoryLevel++;
		}
		public function GetScore() :uint
		{
			var nTempScore :uint = m_nScore;
			nTempScore += (m_nMungLength*500);
			nTempScore += (m_nEatedFoodCount*100);
			nTempScore += (m_nGold*50);
			nTempScore -= uint(m_nElapsedTime*10);
			
			if (nTempScore < 0) nTempScore = 0;
			
			return nTempScore;
		}
		public function CalculateStageScore() :void
		{
			m_nScore += (m_nMungLength*500);
			m_nScore += (m_nEatedFoodCount*100);
			m_nScore += (m_nGold*50);
			m_nScore -= uint(m_nElapsedTime*10);
			
			if (m_nScore < 0) m_nScore = 0;
		}
		public function SetMungLength(nMungLength :int) :void
		{
			m_nMungLength = nMungLength;
			if (m_nHighestMungLength < nMungLength)
			{
				m_nHighestMungLength = nMungLength;
			}
			
			m_nAddPieceCount = m_nMungLength;
		}
		public function GetAddPieceCount() :int
		{
			return Math.floor(Number(m_nAddPieceCount/COUNT_FOR_ADD_PIECE));
		}
		public function ResetAddPieceCount() :void
		{
			m_nAddPieceCount = 0;
		}
		
	}
}